<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Memory Card Game</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Arial', sans-serif;
        }

        body {
            background: linear-gradient(135deg, #2c3e50, #3498db);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            color: white;
        }

        .game-container {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            padding: 2rem;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
            text-align: center;
            max-width: 800px;
            width: 90%;
        }

        .game-header {
            margin-bottom: 2rem;
        }

        .game-title {
            font-size: 2.5rem;
            margin-bottom: 1rem;
            background: linear-gradient(45deg, #f1c40f, #e74c3c);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            animation: titleGlow 2s infinite alternate;
        }

        @keyframes titleGlow {
            from {
                text-shadow: 0 0 10px rgba(241, 196, 15, 0.5);
            }

            to {
                text-shadow: 0 0 20px rgba(231, 76, 60, 0.5);
            }
        }

        .stats {
            display: flex;
            justify-content: space-between;
            margin-bottom: 2rem;
            font-size: 1.2rem;
        }

        .game-board {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 1rem;
            margin-bottom: 2rem;
        }

        .card {
            aspect-ratio: 1;
            border-radius: 10px;
            cursor: pointer;
            position: relative;
            transform-style: preserve-3d;
            transition: transform 0.6s;
        }

        .card.flipped {
            transform: rotateY(180deg);
        }

        .card-front,
        .card-back {
            position: absolute;
            width: 100%;
            height: 100%;
            backface-visibility: hidden;
            border-radius: 10px;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 2rem;
        }

        .card-front {
            background: linear-gradient(45deg, #3498db, #2ecc71);
            transform: rotateY(180deg);
        }

        .card-back {
            background: linear-gradient(45deg, #e74c3c, #f1c40f);
        }

        .controls {
            display: flex;
            justify-content: center;
            gap: 1rem;
        }

        .btn {
            padding: 0.8rem 1.5rem;
            border: none;
            border-radius: 25px;
            background: linear-gradient(45deg, #f1c40f, #e74c3c);
            color: white;
            font-size: 1rem;
            cursor: pointer;
            transition: transform 0.2s, box-shadow 0.2s;
        }

        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
        }

        .message {
            margin-top: 1rem;
            font-size: 1.2rem;
            min-height: 1.5em;
        }

        @media (max-width: 600px) {
            .game-container {
                padding: 1rem;
            }

            .game-title {
                font-size: 2rem;
            }

            .game-board {
                grid-template-columns: repeat(3, 1fr);
                gap: 0.5rem;
            }
        }
    </style>
</head>

<body>
    <div class="game-container">
        <div class="game-header">
            <h1 class="game-title">Memory Match</h1>
            <div class="stats">
                <div>Moves: <span id="moves">0</span></div>
                <div>Time: <span id="time">0</span>s</div>
                <div>Pairs: <span id="pairs">0</span>/8</div>
            </div>
        </div>
        <div class="game-board" id="gameBoard"></div>
        <div class="message" id="message"></div>
        <div class="controls">
            <button class="btn" id="startBtn">Start Game</button>
            <button class="btn" id="resetBtn">Reset</button>
        </div>
    </div>

    <script>
        const gameBoard = document.getElementById('gameBoard');
        const movesElement = document.getElementById('moves');
        const timeElement = document.getElementById('time');
        const pairsElement = document.getElementById('pairs');
        const messageElement = document.getElementById('message');
        const startBtn = document.getElementById('startBtn');
        const resetBtn = document.getElementById('resetBtn');

        const icons = [
            'fa-heart', 'fa-star', 'fa-moon', 'fa-sun',
            'fa-cloud', 'fa-bolt', 'fa-leaf', 'fa-fire'
        ];

        let cards = [];
        let flippedCards = [];
        let matchedPairs = 0;
        let moves = 0;
        let seconds = 0;
        let timer;
        let isGameActive = false;

        function createGameBoard() {
            gameBoard.innerHTML = '';
            cards = [];
            flippedCards = [];
            matchedPairs = 0;
            moves = 0;
            seconds = 0;

            movesElement.textContent = moves;
            timeElement.textContent = seconds;
            pairsElement.textContent = `${matchedPairs}/8`;
            messageElement.textContent = '';

            const shuffledIcons = [...icons, ...icons].sort(() => Math.random() - 0.5);

            shuffledIcons.forEach((icon, index) => {
                const card = document.createElement('div');
                card.className = 'card';
                card.dataset.icon = icon;
                card.dataset.index = index;

                const cardFront = document.createElement('div');
                cardFront.className = 'card-front';
                cardFront.innerHTML = `<i class="fas ${icon}"></i>`;

                const cardBack = document.createElement('div');
                cardBack.className = 'card-back';

                card.appendChild(cardFront);
                card.appendChild(cardBack);
                card.addEventListener('click', () => flipCard(card));
                gameBoard.appendChild(card);
                cards.push(card);
            });
        }

        function flipCard(card) {
            if (!isGameActive || flippedCards.length >= 2 || card.classList.contains('flipped') || card.classList.contains('matched')) {
                return;
            }

            card.classList.add('flipped');
            flippedCards.push(card);

            if (flippedCards.length === 2) {
                moves++;
                movesElement.textContent = moves;
                checkMatch();
            }
        }

        function checkMatch() {
            const [card1, card2] = flippedCards;
            const isMatch = card1.dataset.icon === card2.dataset.icon;

            if (isMatch) {
                card1.classList.add('matched');
                card2.classList.add('matched');
                matchedPairs++;
                pairsElement.textContent = `${matchedPairs}/8`;
                messageElement.textContent = 'Match found!';

                if (matchedPairs === 8) {
                    endGame(true);
                }
            } else {
                setTimeout(() => {
                    card1.classList.remove('flipped');
                    card2.classList.remove('flipped');
                    messageElement.textContent = 'Try again!';
                }, 1000);
            }

            flippedCards = [];
        }

        function startGame() {
            if (isGameActive) return;

            isGameActive = true;
            startBtn.disabled = true;
            createGameBoard();

            timer = setInterval(() => {
                seconds++;
                timeElement.textContent = seconds;
            }, 1000);
        }

        function endGame(isWin) {
            isGameActive = false;
            clearInterval(timer);
            startBtn.disabled = false;

            if (isWin) {
                messageElement.textContent = `Congratulations! You won in ${moves} moves and ${seconds} seconds!`;
            }
        }

        startBtn.addEventListener('click', startGame);
        resetBtn.addEventListener('click', () => {
            clearInterval(timer);
            startGame();
        });
    </script>
</body>

</html>